package nodelab;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class NodeSystem {
	private Map<String, Node> inputMapping;
	private List<Node> activateds;
	private List<Node> currentHiddenNodes;
	private List<Node> lastHiddenNodes;
	private int currentTurn;
	private int lastTurn;
	
	public NodeSystem() {
		inputMapping = new HashMap<String, Node>();
		activateds = new LinkedList<Node>();
		currentHiddenNodes = new LinkedList<Node>();
		lastHiddenNodes = new LinkedList<Node>();
		currentTurn = -1;
	}
	
	public int getCurrentTurn() {
		return currentTurn;
	}
	
	public void input(String[] words) {
		for(String word : words) {
			lastHiddenNodes = currentHiddenNodes;
			currentHiddenNodes = new LinkedList<Node>();
			activateds.clear();
			checkingExisting(word);
			Node n = inputMapping.get(word);
			activateds.add(n);
		}
	}
	
	private void checkingExisting(String word) {
		if(!inputMapping.containsKey(word)) {
			inputMapping.put(word, new Node());
		}
	}
	
	public void addCurrentHiddenNode(Node n) {
		currentHiddenNodes.add(n);
	}
	
	public List<Node> getLastHiddenNodes() {
		return lastHiddenNodes;
	}
	
	public List<Node> getPreActivated() {
		return activateds;
	}
	
	public boolean isNeighborTurn(int lastTurn) {
		return this.lastTurn == lastTurn;
	}
}